<?php

class Application_Model_DbTable_Encontro extends Zend_Db_Table_Abstract
{

    protected $_name = 'encontro';

    public function getListaEncontros($where="1"){
    	$select = $this->select()
    	->setIntegrityCheck(false)
    	->from(array("e"=> $this->_name))
    	->joinInner(array('pa'=>'paroquia'), 'pa.id_paroquia = e.id_paroquia', array("nome_paroquia" => 'pa.nome'))
    	->where($where);
    	return $this->fetchAll($select);
    }
    
    public function getProximoEdicaoParoquia($idParoquia){
    	$select = $this->select()
    	->setIntegrityCheck(false)
    	->from(array("e"=> $this->_name), array("edicao" => new Zend_Db_Expr('(MAX(e.edicao)+1)'), "ano" => new Zend_Db_Expr('(MAX(e.ano)+1)')))
    	->where("id_paroquia = ".$idParoquia)
    	->group("id_paroquia")
    	->order("edicao");
    	return $this->fetchRow($select);
    }
    
    public function eResponsavel($idEncontro, $idParoquia){
    	$idParoquia = 2;
    	$select = $this->select()
    	->setIntegrityCheck(false)
    	->from(array("e"=> $this->_name), array("total" => new Zend_Db_Expr('COUNT(*)')))
    	->where("id_paroquia = ".$idParoquia)
    	->where("id_encontro = ".$idEncontro);
    	$retorno = $this->fetchRow($select);
    	
    	if($retorno->total > 0){
    		return true;
    	}else{
    		return false;
    	}
    }
}

